VERSION 5.00
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Object = "{CDE57A40-8B86-11D0-B3C6-00A0C90AEA82}#1.0#0"; "msdatgrd.ocx"
Object = "{B3FB64BF-91F9-11D7-A482-0008A14158BC}#2.22#0"; "itgcontrols.ocx"
Begin VB.Form frmARCashSales 
   BackColor       =   &H00F7D9C2&
   BorderStyle     =   0  'None
   Caption         =   "Form1"
   ClientHeight    =   8235
   ClientLeft      =   0
   ClientTop       =   -45
   ClientWidth     =   12165
   BeginProperty Font 
      Name            =   "Tahoma"
      Size            =   8.25
      Charset         =   0
      Weight          =   400
      Underline       =   0   'False
      Italic          =   0   'False
      Strikethrough   =   0   'False
   EndProperty
   KeyPreview      =   -1  'True
   LinkTopic       =   "Form1"
   MaxButton       =   0   'False
   MDIChild        =   -1  'True
   MinButton       =   0   'False
   ScaleHeight     =   8235
   ScaleWidth      =   12165
   ShowInTaskbar   =   0   'False
   Begin ITGControls.ComunionFrames ComunionFrames3 
      Height          =   2040
      Left            =   0
      Top             =   5595
      Width           =   12000
      _ExtentX        =   21167
      _ExtentY        =   3598
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Payment"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.ComboBox cboCS_C 
         Height          =   315
         ItemData        =   "frmARCashSales.frx":0000
         Left            =   90
         List            =   "frmARCashSales.frx":0002
         Style           =   2  'Dropdown List
         TabIndex        =   47
         Top             =   990
         Visible         =   0   'False
         Width           =   1260
      End
      Begin MSDataGridLib.DataGrid dtgPayment 
         Height          =   1620
         Left            =   0
         TabIndex        =   27
         Top             =   420
         Width           =   12000
         _ExtentX        =   21167
         _ExtentY        =   2858
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   10
         BeginProperty Column00 
            DataField       =   "cType"
            Caption         =   "Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cAuthorization"
            Caption         =   "Authorization Code"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cCCardType"
            Caption         =   "Credit Card Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cBankID"
            Caption         =   "Bank ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cCCardNo"
            Caption         =   "Card Number"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "dExpiration"
            Caption         =   "Expiration"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "nCash"
            Caption         =   "Cash"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nChange"
            Caption         =   "Change"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "nAmount"
            Caption         =   "Amount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   929.764
            EndProperty
            BeginProperty Column01 
            EndProperty
            BeginProperty Column02 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1620.284
            EndProperty
            BeginProperty Column03 
               Button          =   -1  'True
               ColumnWidth     =   1335.118
            EndProperty
            BeginProperty Column04 
               ColumnWidth     =   1590.236
            EndProperty
            BeginProperty Column05 
               ColumnWidth     =   1124.787
            EndProperty
            BeginProperty Column06 
               Object.Visible         =   0   'False
               ColumnWidth     =   1094.74
            EndProperty
            BeginProperty Column07 
               ColumnWidth     =   1260.284
            EndProperty
            BeginProperty Column08 
               Object.Visible         =   0   'False
            EndProperty
            BeginProperty Column09 
               Locked          =   -1  'True
               ColumnWidth     =   1544.882
            EndProperty
         EndProperty
      End
   End
   Begin ITGControls.ComunionFrames ComunionFrames2 
      Height          =   2235
      Left            =   0
      Top             =   3375
      Width           =   12000
      _ExtentX        =   21167
      _ExtentY        =   3942
      FrameColor      =   4210752
      BackColor       =   16243138
      FillColor       =   16243138
      RoundedCorner   =   0   'False
      Caption         =   "Details"
      Alignment       =   0
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      ThemeColor      =   5
      ColorFrom       =   16243138
      ColorTo         =   16250865
      Begin VB.ComboBox cboSI 
         Height          =   315
         ItemData        =   "frmARCashSales.frx":0004
         Left            =   90
         List            =   "frmARCashSales.frx":0006
         Style           =   2  'Dropdown List
         TabIndex        =   46
         Top             =   945
         Visible         =   0   'False
         Width           =   1440
      End
      Begin VB.TextBox txtLongDesc 
         Appearance      =   0  'Flat
         DataField       =   "cLongDesc"
         Height          =   1080
         Left            =   1530
         MaxLength       =   1000
         MultiLine       =   -1  'True
         TabIndex        =   45
         Top             =   945
         Visible         =   0   'False
         Width           =   4020
      End
      Begin MSDataGridLib.DataGrid dtgSI 
         Height          =   1815
         Left            =   0
         TabIndex        =   26
         Top             =   420
         Width           =   12000
         _ExtentX        =   21167
         _ExtentY        =   3201
         _Version        =   393216
         AllowUpdate     =   -1  'True
         AllowArrows     =   -1  'True
         Appearance      =   0
         BackColor       =   16777215
         HeadLines       =   1
         RowHeight       =   15
         TabAcrossSplits =   -1  'True
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   11
         BeginProperty Column00 
            DataField       =   "cItemNo"
            Caption         =   "Product ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "cDesc"
            Caption         =   "Product Description"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cUnit"
            Caption         =   "Unit"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "nQty"
            Caption         =   "Quantity"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cPricing"
            Caption         =   "Pricing"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00000000"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "nUDPrice"
            Caption         =   "Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "cDiscount"
            Caption         =   "Discount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "nPrice"
            Caption         =   "Net Price"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column08 
            DataField       =   "nAmount"
            Caption         =   "Amount"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column09 
            DataField       =   "cBarcodeID"
            Caption         =   "Barcode ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column10 
            DataField       =   "cWH"
            Caption         =   "Warehouse"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            BeginProperty Column00 
               Button          =   -1  'True
               ColumnWidth     =   1154.835
            EndProperty
            BeginProperty Column01 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   2505.26
            EndProperty
            BeginProperty Column02 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   780.095
            EndProperty
            BeginProperty Column03 
               Alignment       =   1
               ColumnWidth     =   1019.906
            EndProperty
            BeginProperty Column04 
               Button          =   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   989.858
            EndProperty
            BeginProperty Column05 
               Alignment       =   1
               ColumnWidth     =   1019.906
            EndProperty
            BeginProperty Column06 
               Object.Visible         =   -1  'True
               ColumnWidth     =   1080
            EndProperty
            BeginProperty Column07 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1110.047
            EndProperty
            BeginProperty Column08 
               Locked          =   -1  'True
            EndProperty
            BeginProperty Column09 
               Alignment       =   1
               Locked          =   -1  'True
               Object.Visible         =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column10 
               Button          =   -1  'True
               Locked          =   -1  'True
               Object.Visible         =   0   'False
               ColumnWidth     =   1154.835
            EndProperty
         EndProperty
      End
   End
   Begin ITGControls.ITGTab SSTab1 
      Height          =   7635
      Left            =   0
      TabIndex        =   29
      Top             =   0
      Width           =   12000
      _ExtentX        =   21167
      _ExtentY        =   13467
      TabCount        =   2
      TabCaption(0)   =   "               Main               "
      TabContCtrlCnt(0)=   6
      Tab(0)ContCtrlCap(1)=   "txtBalance"
      Tab(0)ContCtrlCap(2)=   "txtCredit"
      Tab(0)ContCtrlCap(3)=   "txtDebit"
      Tab(0)ContCtrlCap(4)=   "txtPayment"
      Tab(0)ContCtrlCap(5)=   "txtReturns"
      Tab(0)ContCtrlCap(6)=   "ComunionFrames1"
      TabCaption(1)   =   "               List               "
      TabContCtrlCnt(1)=   1
      Tab(1)ContCtrlCap(1)=   "dtgList"
      TabTheme        =   2
      ActiveTabBackStartColor=   16250865
      ActiveTabBackEndColor=   16243138
      InActiveTabBackStartColor=   16243138
      InActiveTabBackEndColor=   16243138
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   4210752
      TopLeftInnerBorderColor=   4210752
      BottomRightInnerBorderColor=   4210752
      DisabledTabBackColor=   -2147483633
      DisabledTabForeColor=   -2147483631
      Begin MSDataGridLib.DataGrid dtgList 
         Height          =   3075
         Left            =   -75000
         TabIndex        =   28
         Top             =   315
         Width           =   11880
         _ExtentX        =   20955
         _ExtentY        =   5424
         _Version        =   393216
         AllowUpdate     =   0   'False
         AllowArrows     =   -1  'True
         Appearance      =   0
         HeadLines       =   1
         RowHeight       =   15
         TabAction       =   2
         FormatLocked    =   -1  'True
         BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ColumnCount     =   8
         BeginProperty Column00 
            DataField       =   "cInvNo"
            Caption         =   "Invoice No."
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column01 
            DataField       =   "dDate"
            Caption         =   "Date"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "MM/dd/yyyy"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   3
            EndProperty
         EndProperty
         BeginProperty Column02 
            DataField       =   "cCode"
            Caption         =   "Customer ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column03 
            DataField       =   "cType"
            Caption         =   "Invoice Type"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column04 
            DataField       =   "cSMan"
            Caption         =   "Salesman ID"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column05 
            DataField       =   "cMSCode"
            Caption         =   "Market Segment"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         BeginProperty Column06 
            DataField       =   "nGross"
            Caption         =   "Gross"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   1
               Format          =   "#,##0.00"
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   1
            EndProperty
         EndProperty
         BeginProperty Column07 
            DataField       =   "cRemarks"
            Caption         =   "Remarks"
            BeginProperty DataFormat {6D835690-900B-11D0-9484-00A0C91110ED} 
               Type            =   0
               Format          =   ""
               HaveTrueFalseNull=   0
               FirstDayOfWeek  =   0
               FirstWeekOfYear =   0
               LCID            =   1033
               SubFormatType   =   0
            EndProperty
         EndProperty
         SplitCount      =   1
         BeginProperty Split0 
            AllowRowSizing  =   0   'False
            BeginProperty Column00 
               ColumnAllowSizing=   -1  'True
               Locked          =   -1  'True
               ColumnWidth     =   1319.811
            EndProperty
            BeginProperty Column01 
               Locked          =   -1  'True
               ColumnWidth     =   1154.835
            EndProperty
            BeginProperty Column02 
               Locked          =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column03 
               Locked          =   -1  'True
               ColumnWidth     =   1289.764
            EndProperty
            BeginProperty Column04 
               Locked          =   -1  'True
               ColumnWidth     =   1305.071
            EndProperty
            BeginProperty Column05 
               Locked          =   -1  'True
               ColumnWidth     =   1365.165
            EndProperty
            BeginProperty Column06 
               Alignment       =   1
               Locked          =   -1  'True
               ColumnWidth     =   1260.284
            EndProperty
            BeginProperty Column07 
               Locked          =   -1  'True
               ColumnWidth     =   2459.906
            EndProperty
         EndProperty
      End
      Begin ITGControls.ITGTextBox txtBalance 
         Height          =   285
         Left            =   8415
         TabIndex        =   42
         TabStop         =   0   'False
         Top             =   9960
         Width           =   2385
         _ExtentX        =   3995
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Balance"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1325
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtCredit 
         Height          =   285
         Left            =   8415
         TabIndex        =   41
         TabStop         =   0   'False
         Top             =   9600
         Width           =   2385
         _ExtentX        =   3995
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Credit"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1325
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtDebit 
         Height          =   285
         Left            =   8415
         TabIndex        =   40
         TabStop         =   0   'False
         Top             =   9240
         Width           =   2370
         _ExtentX        =   3969
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Debit"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1310
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtPayment 
         Height          =   285
         Left            =   5640
         TabIndex        =   39
         TabStop         =   0   'False
         Top             =   9960
         Width           =   2385
         _ExtentX        =   3995
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Payment"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1325
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ITGTextBox txtReturns 
         Height          =   285
         Left            =   5640
         TabIndex        =   38
         TabStop         =   0   'False
         Top             =   9600
         Width           =   2385
         _ExtentX        =   3995
         _ExtentY        =   503
         SendKeysTab     =   -1  'True
         BackColor       =   14737632
         LabelBackColor  =   16243138
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Text            =   "0"
         DataType        =   1
         DecimalPlace    =   2
         Label           =   "Returns"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         LabelWidth      =   1000
         TextBoxWidth    =   1325
         Enabled         =   0   'False
         LinkForeColor   =   0
      End
      Begin ITGControls.ComunionFrames ComunionFrames1 
         Height          =   3075
         Left            =   0
         Top             =   315
         Width           =   12000
         _ExtentX        =   21167
         _ExtentY        =   5424
         FrameColor      =   4210752
         BackColor       =   16243138
         FillColor       =   16243138
         RoundedCorner   =   0   'False
         Caption         =   "Sales Invoice Information"
         Alignment       =   0
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   700
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         ThemeColor      =   5
         ColorFrom       =   16243138
         ColorTo         =   16250865
         Begin VB.Timer Timer1 
            Interval        =   300
            Left            =   2790
            Top             =   390
         End
         Begin VB.CommandButton cmdPickMS 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2685
            Picture         =   "frmARCashSales.frx":0008
            Style           =   1  'Graphical
            TabIndex        =   7
            Top             =   1125
            Width           =   315
         End
         Begin VB.ComboBox cboIntTerms 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   9150
            Style           =   2  'Dropdown List
            TabIndex        =   13
            Top             =   1440
            Visible         =   0   'False
            Width           =   1515
         End
         Begin VB.CommandButton cmdPickCode 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2685
            Picture         =   "frmARCashSales.frx":0152
            Style           =   1  'Graphical
            TabIndex        =   3
            Top             =   810
            Width           =   315
         End
         Begin VB.CommandButton cmdPickSM 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2685
            Picture         =   "frmARCashSales.frx":029C
            Style           =   1  'Graphical
            TabIndex        =   15
            Top             =   1755
            Width           =   315
         End
         Begin VB.ComboBox cboTerms 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   9150
            Style           =   2  'Dropdown List
            TabIndex        =   17
            Top             =   1755
            Visible         =   0   'False
            Width           =   1515
         End
         Begin VB.CommandButton cmdPickPD 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2685
            Picture         =   "frmARCashSales.frx":03E6
            Style           =   1  'Graphical
            TabIndex        =   11
            Top             =   1440
            Width           =   315
         End
         Begin VB.CommandButton cmdPickPC 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2685
            Picture         =   "frmARCashSales.frx":0530
            Style           =   1  'Graphical
            TabIndex        =   22
            Top             =   2385
            Visible         =   0   'False
            Width           =   315
         End
         Begin VB.CommandButton cmdPickWH 
            Enabled         =   0   'False
            BeginProperty Font 
               Name            =   "MS Sans Serif"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Height          =   300
            Left            =   2685
            Picture         =   "frmARCashSales.frx":067A
            Style           =   1  'Graphical
            TabIndex        =   19
            Top             =   2070
            Width           =   315
         End
         Begin VB.ComboBox cboPaymentType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            Left            =   9150
            Style           =   2  'Dropdown List
            TabIndex        =   5
            Top             =   810
            Width           =   1515
         End
         Begin ITGControls.ITGTextBox txtWHName 
            Height          =   285
            Left            =   3000
            TabIndex        =   20
            TabStop         =   0   'False
            Top             =   2070
            Width           =   3720
            _ExtentX        =   6456
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3660
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtWH 
            Height          =   285
            Left            =   120
            TabIndex        =   18
            Top             =   2070
            Width           =   2535
            _ExtentX        =   4260
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "Van\Warehouse"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1125
         End
         Begin ITGControls.ITGDateBox dtbDate 
            Height          =   285
            Left            =   9150
            TabIndex        =   1
            Tag             =   "Invoice Date"
            Top             =   495
            Width           =   1515
            _ExtentX        =   2672
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   ""
            SendKeysTab     =   -1  'True
            Mandatory       =   -1  'True
         End
         Begin ITGControls.ITGTextBox txtInvNo 
            Height          =   285
            Left            =   120
            TabIndex        =   0
            Top             =   495
            Width           =   2535
            _ExtentX        =   4260
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Invoice No."
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1125
         End
         Begin ITGControls.ITGTextBox txtName 
            Height          =   285
            Left            =   3000
            TabIndex        =   4
            TabStop         =   0   'False
            Top             =   810
            Width           =   3720
            _ExtentX        =   6456
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3660
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtCode 
            Height          =   285
            Left            =   120
            TabIndex        =   2
            Top             =   810
            Width           =   2535
            _ExtentX        =   4260
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Customer"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1125
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtRemarks 
            Height          =   285
            Left            =   120
            TabIndex        =   24
            Top             =   2700
            Width           =   6615
            _ExtentX        =   11456
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Remarks"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   5205
            LinkForeColor   =   0
         End
         Begin ITGControls.ITGTextBox txtSMName 
            Height          =   285
            Left            =   3000
            TabIndex        =   16
            TabStop         =   0   'False
            Top             =   1755
            Width           =   3720
            _ExtentX        =   6456
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3660
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtSMCode 
            Height          =   285
            Left            =   120
            TabIndex        =   14
            Top             =   1755
            Width           =   2535
            _ExtentX        =   4260
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Salesman"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1125
            LinkForeColor   =   16711680
         End
         Begin ITGControls.ITGTextBox txtIntTerms 
            Height          =   285
            Left            =   10215
            TabIndex        =   32
            Tag             =   "cboIntTerms"
            Top             =   1845
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Internal Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGTextBox txtTerms 
            Height          =   285
            Left            =   10215
            TabIndex        =   33
            Tag             =   "cboIntTerms"
            Top             =   2130
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Mandatory       =   -1  'True
            Label           =   "Internal Terms"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin ITGControls.ITGTextBox txtMSDesc 
            Height          =   285
            Left            =   3000
            TabIndex        =   8
            TabStop         =   0   'False
            Top             =   1125
            Width           =   3720
            _ExtentX        =   6456
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3660
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtMSCode 
            Height          =   285
            Left            =   120
            TabIndex        =   6
            Top             =   1125
            Width           =   2535
            _ExtentX        =   4260
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Market Segment"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1125
         End
         Begin ITGControls.ITGTextBox txtPDDesc 
            Height          =   285
            Left            =   3000
            TabIndex        =   12
            TabStop         =   0   'False
            Top             =   1440
            Width           =   3720
            _ExtentX        =   6456
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3660
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtPDCode 
            Height          =   285
            Left            =   120
            TabIndex        =   10
            Top             =   1440
            Width           =   2535
            _ExtentX        =   4260
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14745599
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Product Division"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1125
         End
         Begin ITGControls.ITGTextBox txtPCDesc 
            Height          =   285
            Left            =   3000
            TabIndex        =   23
            TabStop         =   0   'False
            Top             =   2385
            Visible         =   0   'False
            Width           =   3720
            _ExtentX        =   6456
            _ExtentY        =   503
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Label           =   "ITGtext"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   3660
            Enabled         =   0   'False
         End
         Begin ITGControls.ITGTextBox txtPCCode 
            Height          =   285
            Left            =   120
            TabIndex        =   21
            Top             =   2385
            Visible         =   0   'False
            Width           =   2535
            _ExtentX        =   4260
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            AllCaps         =   -1  'True
            Mandatory       =   -1  'True
            Label           =   "Profit Center"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1350
            TextBoxWidth    =   1125
         End
         Begin ITGControls.ITGTextBox txtVatType 
            Height          =   285
            Left            =   9855
            TabIndex        =   44
            Tag             =   "cboPaymentType"
            Top             =   1560
            Visible         =   0   'False
            Width           =   1515
            _ExtentX        =   2566
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Payment Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1455
         End
         Begin ITGControls.ITGTextBox txtGross 
            Height          =   285
            Left            =   7905
            TabIndex        =   25
            TabStop         =   0   'False
            Top             =   2700
            Width           =   2730
            _ExtentX        =   4604
            _ExtentY        =   503
            SendKeysTab     =   -1  'True
            BackColor       =   14737632
            LabelBackColor  =   16243138
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Text            =   "0"
            DataType        =   1
            DecimalPlace    =   2
            Label           =   "Gross"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   1250
            TextBoxWidth    =   1420
            Enabled         =   0   'False
            LinkForeColor   =   0
         End
         Begin VB.ComboBox cboVatType 
            Appearance      =   0  'Flat
            BackColor       =   &H00FFFFFF&
            Height          =   315
            ItemData        =   "frmARCashSales.frx":07C4
            Left            =   9150
            List            =   "frmARCashSales.frx":07C6
            Style           =   2  'Dropdown List
            TabIndex        =   9
            Top             =   1125
            Width           =   1515
         End
         Begin ITGControls.ITGTextBox txtPaymentType 
            Height          =   285
            Left            =   10200
            TabIndex        =   31
            Tag             =   "cboPaymentType"
            Top             =   1260
            Visible         =   0   'False
            Width           =   1155
            _ExtentX        =   1931
            _ExtentY        =   503
            BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            Label           =   "Payment Type"
            BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
               Name            =   "Tahoma"
               Size            =   8.25
               Charset         =   0
               Weight          =   400
               Underline       =   0   'False
               Italic          =   0   'False
               Strikethrough   =   0   'False
            EndProperty
            LabelWidth      =   0
            TextBoxWidth    =   1095
         End
         Begin VB.Label Label6 
            BackColor       =   &H00F7D9C2&
            Caption         =   "VAT Type"
            Height          =   285
            Left            =   7920
            TabIndex        =   43
            Top             =   1125
            Width           =   705
         End
         Begin VB.Label Label1 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Date"
            Height          =   285
            Left            =   7935
            TabIndex        =   37
            Top             =   495
            Width           =   1305
         End
         Begin VB.Label Label3 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Payment Type"
            Height          =   285
            Left            =   7935
            TabIndex        =   36
            Top             =   810
            Width           =   1305
         End
         Begin VB.Label Label4 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Internal Terms"
            Height          =   285
            Index           =   1
            Left            =   7935
            TabIndex        =   35
            Top             =   1440
            Visible         =   0   'False
            Width           =   1365
         End
         Begin VB.Label Label2 
            BackColor       =   &H00F7D9C2&
            Caption         =   "Actual Terms"
            Height          =   285
            Index           =   1
            Left            =   7935
            TabIndex        =   34
            Top             =   1755
            Visible         =   0   'False
            Width           =   1365
         End
      End
   End
   Begin MSComctlLib.StatusBar sbRS 
      Align           =   2  'Align Bottom
      Height          =   285
      Left            =   0
      TabIndex        =   30
      Top             =   7950
      Width           =   12165
      _ExtentX        =   21458
      _ExtentY        =   503
      _Version        =   393216
      BeginProperty Panels {8E3867A5-8586-11D1-B16A-00C0F0283628} 
         NumPanels       =   5
         BeginProperty Panel1 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel2 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
         EndProperty
         BeginProperty Panel3 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Alignment       =   1
            AutoSize        =   1
            Bevel           =   0
            Object.Width           =   8231
            MinWidth        =   2
         EndProperty
         BeginProperty Panel4 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
         BeginProperty Panel5 {8E3867AB-8586-11D1-B16A-00C0F0283628} 
            Object.Width           =   3528
            MinWidth        =   3528
         EndProperty
      EndProperty
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
   End
End
Attribute VB_Name = "frmARCashSales"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
'IT Group Inc. 2005.08.16

Option Explicit

'Object variables




Private oPrint As New clsPrinting


'Recordset variables
Private WithEvents rsHeader As ADODB.Recordset
Attribute rsHeader.VB_VarHelpID = -1
Private rsDetail As ADODB.Recordset
Private rsPayment As ADODB.Recordset
Private rsCCard As ADODB.Recordset

'ADO Connection variables

Private connHeader As ADODB.Connection
Private connDetail As ADODB.Connection
Private connPayment As ADODB.Connection

'Form mode enumeration
Enum eSIVSMode
    Normal
    AddNewEdit
    Find
End Enum
Public Mode As eSIVSMode

'Other declarations
Private lLessAmount As Boolean
Private lLessPercent As Boolean
Private lNetOK As Boolean

Public dtgName As String
Public sBit As String
Private vBM As Variant 'Recordset bookmark variable
Private strNo As String

Dim aQty(0 To 999) As Double

Dim nSRP(0 To 999) As Double
Dim nWSP(0 To 999) As Double
Dim nNewQtyBoundary(0 To 999) As Double
Dim nPaid, nAmount, nPAmount, nCash As Double

'Security Acess Level variables
Public lACNew As Boolean
Public lACEdit As Boolean
Public lACDelete As Boolean
Public lACPost As Boolean
Public lACCancel As Boolean
Public lACPrint As Boolean

Dim sType As String

Private Sub cboCS_C_Click()
    If dtgPayment.Col = 0 Then
        rsPayment!cType = cboCS_C
    ElseIf dtgPayment.Col = 2 Then
        rsPayment!cCCardType = cboCS_C
'        dtgPayment.Columns(2).Text = cboCS_C
    End If
End Sub

Private Sub cboCS_C_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgPayment.Col = 0 Then
            rsPayment!cType = cboCS_C
            cboCS_C.Visible = False
            If rsPayment!cType = "CSH" Then
                dtgPayment.Col = 7
                dtgPayment.SetFocus
            Else
                dtgPayment.Col = 1
                dtgPayment.SetFocus
            End If
        ElseIf dtgPayment.Col = 2 Then
            rsPayment!cCCardType = cboCS_C
'            dtgPayment.Columns(2).Text = cboCS_C
            cboCS_C.Visible = False
            dtgPayment.Col = 3
            dtgPayment.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboCS_C.Visible = False
    End If
End Sub

Private Sub cboCS_C_KeyPress(KeyAscii As Integer)
If Mode <> AddNewEdit Then Exit Sub
    If rsPayment.RecordCount = 0 Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    If KeyAscii = 13 Then
        If rsPayment!cType = "CSH" Then
            cboCS_C.Visible = False
            dtgPayment.Col = 7
            dtgPayment.SetFocus
        End If
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii))) 'All Upper Case String
    End If
End Sub

Private Sub cboCS_C_LostFocus()
cboCS_C.Visible = False
End Sub

Private Sub cboIntTerms_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboPaymentType_Click()
    txtPaymentType = Trim(cboPaymentType)
End Sub

Private Sub cboPaymentType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboVatType_Click()
    txtPaymentType = Trim(cboPaymentType)
End Sub

Private Sub cboVatType_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboSI_Click()
    If dtgSI.Col = 4 Then
        If Trim(cboSI) <> "" Then
            rsDetail!cPricing = cboSI
            Select Case Trim(cboSI)
                Case "SRP"
                    rsDetail!nUDPrice = IIf(nSRP(rsDetail.AbsolutePosition) <> 0, nSRP(rsDetail.AbsolutePosition), Trim(GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & "")
                Case "Wholesaler"
                    rsDetail!nUDPrice = IIf(nWSP(rsDetail.AbsolutePosition) <> 0, nWSP(rsDetail.AbsolutePosition), Trim(GetValueFrTable("nWSPrice", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & "")
                
                Case "Member"
                    GetCustFromPM
                Case "Wholesaler"
                    GetCustFromPM
                Case "Pricing Client"
                    GetCustFromPM
                Case Else
                    rsDetail!nUDPrice = 0
            End Select
            ComputeNet
            ComputeAmount
            ComputeTotal
        End If
    ElseIf dtgSI.Col = 2 Then
        rsDetail!cUnit = cboSI
        rsDetail!nQty = GetActualUnitQty(aQty(rsDetail.AbsolutePosition), dtgSI.Columns(0).Value, dtgSI.Columns(2).Value)
        Select Case rsDetail!cPricing
            Case "SRP"
                rsDetail!nUDPrice = nSRP(rsDetail.AbsolutePosition)
            Case "WSP"
                rsDetail!nUDPrice = nWSP(rsDetail.AbsolutePosition)
'            Case Else
'                rsDetail!nUDPrice = 0
        End Select
        ComputeNet
        ComputeAmount
        ComputeTotal
    End If
End Sub

Private Sub cboSI_KeyDown(KeyCode As Integer, Shift As Integer)
    If KeyCode = 13 Then
        If dtgSI.Col = 4 Then
            rsDetail!cPricing = cboSI
            cboSI.Visible = False
            dtgSI.Col = 5
            dtgSI.SetFocus
        ElseIf dtgSI.Col = 2 Then
            rsDetail!cUnit = cboSI
            cboSI.Visible = False
            dtgSI.Col = 3
            dtgSI.SetFocus
        End If
    ElseIf KeyCode = vbKeyEscape Then
        cboSI.Visible = False
    End If
End Sub

Private Sub cboSI_LostFocus()
    cboSI.Visible = False
End Sub

Private Sub cboTerms_KeyPress(KeyAscii As Integer)
    SendKeysTab KeyAscii
End Sub

Private Sub cboIntTerms_Click()
    txtIntTerms = Trim(cboIntTerms)
End Sub

Private Sub cboTerms_Click()
    txtTerms = Trim(cboTerms)
End Sub

'Call pick list module
Private Sub cmdPickCode_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtCode)
    frmITGPicker.zType = QCustomer
    frmITGPicker.Show vbModal
    'rsHeader!cCode = frmITGPicker.zCode
     txtCode.Text = frmITGPicker.zCode
    txtName = frmITGPicker.zName
End Sub

Private Sub cmdPickMS_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtMSCode)
    frmITGPicker.zType = QMarketSegment
    frmITGPicker.Show vbModal
    txtMSCode.Text = frmITGPicker.zCode
    txtMSCode = frmITGPicker.zName
    If Trim(txtMSDesc) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickPC_Click()
    If lPickListActive Then Exit Sub
    frmITGPickList.mType = ProfitCenter
    frmITGPickList.Show vbModal
    rsHeader!cPCCode = frmITGPickList.mCode
    txtPCCode = frmITGPickList.mCode
    If Trim(txtPCDesc) <> "" Then SendKeys "{Tab}"
End Sub



Private Sub cmdPickSM_Click()
    If lPickListActive Then Exit Sub
    sFilterString = Trim(txtSMCode)
    frmITGPicker.zType = QSalesman
    frmITGPicker.Show vbModal
    txtSMCode.Text = frmITGPicker.zCode
    txtSMName = frmITGPicker.zName
    If Trim(txtSMName) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub cmdPickWH_Click()
    If lPickListActive Then Exit Sub
    frmITGPickList.mType = Warehouse
    frmITGPickList.Show vbModal
    txtWH = frmITGPickList.mCode
    If Trim(txtWH) <> "" Then SendKeys "{Tab}"
End Sub

Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
    SortGrid dtgList, ColIndex, rsHeader
End Sub

Private Sub dtgPayment_AfterColUpdate(ByVal ColIndex As Integer)
On Error Resume Next
If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 7
            
            TotalAmount
            Do While IsNull(rsPayment!nCash) = True
                rsPayment.MovePrevious
            Loop
            If rsPayment!nCash > nAmount And nPAmount = 0 Then
                rsPayment!nChange = rsPayment!nCash - nAmount
                rsPayment!nAmount = nAmount
            ElseIf rsPayment!nCash = nAmount And nPAmount = 0 Then
                rsPayment!nChange = 0
                rsPayment!nAmount = rsPayment!nCash
            ElseIf rsPayment!nCash < nAmount And nPAmount = 0 Then
                rsPayment!nAmount = rsPayment!nCash
                rsPayment!nChange = 0
            ElseIf rsPayment!nCash < nAmount And nPAmount > 0 And rsPayment!nCash > (nAmount - nPAmount) Then
                rsPayment!nAmount = nAmount - nPAmount
                rsPayment!nChange = rsPayment!nCash - (nAmount - nPAmount)
            ElseIf rsPayment!nCash < nAmount And nPAmount > 0 And rsPayment!nCash < (nAmount - nPAmount) Then
                rsPayment!nAmount = rsPayment!nCash
                rsPayment!nChange = 0
            End If
            
    End Select
End Sub

Private Sub dtgPayment_ButtonClick(ByVal ColIndex As Integer)
If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 0 'Payment type
            Call LoadComboValues(cboCS_C, "cValue", "PARAMETER_USER", "WHERE cCompanyID = '" & COID & "' AND cType = 'PAYTYPE' and cParamName <> 'CHK'", "nOrder")
            Call MoveCombo(cboCS_C, dtgPayment, dtgPayment.Columns(0))
            ComboLoadValue cboCS_C, Trim(dtgPayment.Columns(0).Text)
        Case 2 'Credit card type
            Call LoadComboValues(cboCS_C, "cValue", "PARAMETER_USER", "WHERE cCompanyID = '" & COID & "' AND cType = 'CCARDTYPE'", "nOrder")
            Call MoveCombo(cboCS_C, dtgPayment, dtgPayment.Columns(2))
            ComboLoadValue cboCS_C, Trim(dtgPayment.Columns(2).Text)
        Case 3 'Bank ID
            If lPickListActive Then Exit Sub
            frmITGPickList.mType = Bank
            frmITGPickList.Show vbModal
            If Trim(frmITGPickList.mCode) = "" Then Exit Sub
            dtgPayment.Columns(3).Value = frmITGPickList.mName & ""
            If dtgPayment.Columns(1).Text <> "" And dtgPayment.Columns(3).Text <> "" Then
                If AuthorExisting(dtgPayment.Columns(1).Text, dtgPayment.Columns(3).Text, rsCCard, True) Then
                    MsgBox "Authorization already exist."
                    dtgPayment.Col = 3
                   Exit Sub
                End If
            End If
            dtgPayment.Col = 4
            dtgPayment.Columns(4).Value = rsPayment!cCCardNo
    End Select
End Sub

Private Sub dtgPayment_Click()
    If Mode = AddNewEdit Then dtgName = dtgPayment.Name
End Sub

Private Sub dtgPayment_Error(ByVal DataError As Integer, Response As Integer)
If Mode <> AddNewEdit Then
        Response = 0
        Exit Sub
    End If
    If DataError = 7007 Then
        MsgBox "Type mismatch", vbExclamation, "ComUnion"
    ElseIf DataError = 13 Then
        MsgBox "Type mismatch", vbExclamation, "ComUnion"
    End If
    Response = 0
End Sub

Private Sub dtgPayment_GotFocus()
    dtgName = dtgPayment.Name
End Sub

Private Sub dtgPayment_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    End If
End Sub

Private Sub dtgPayment_KeyPress(KeyAscii As Integer)
If Mode <> AddNewEdit Then Exit Sub
    If rsPayment.RecordCount = 0 Then Exit Sub
    
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    If KeyAscii = 13 Then
        Select Case dtgPayment.Col
            Case 0
                If Not cboCS_C.Visible Then dtgPayment_ButtonClick 0
                cboCS_C.SetFocus
                If rsPayment!cType = "CSH" Then
                    dtgPayment.Col = 7
                End If
            Case 1
                If dtgPayment.Columns(1).Text <> "" And dtgPayment.Columns(3).Text <> "" Then
                    If AuthorExisting(dtgPayment.Columns(1).Text, dtgPayment.Columns(3).Text, rsCCard, True) Then
                        MsgBox "Authorization already exist."
                        dtgPayment.Col = 1
                        Exit Sub
                    End If
                ElseIf Trim(dtgPayment.Columns(1).Text) = "" Then
                    MsgBox "Authorization Code is required."
                    dtgPayment.Col = 1
                    Exit Sub
                Else
                    SendKeys "{Tab}"
                End If
            Case 2
                If Not cboCS_C.Visible Then dtgPayment_ButtonClick 2
            Case 3
                dtgPayment_ButtonClick 3
                If dtgPayment.Columns(1).Text <> "" And dtgPayment.Columns(3).Text <> "" Then
                    If AuthorExisting(dtgPayment.Columns(1).Text, dtgPayment.Columns(3).Text, rsCCard, True) Then
                        MsgBox "Authorization already exist."
                        dtgPayment.Col = 3
                        Exit Sub
                    End If
                End If
            Case 4
                If Trim(dtgPayment.Columns(4).Text) = "" Then
                    MsgBox "Credit Card Number is required."
                    dtgPayment.Col = 4
                    Exit Sub
                Else
                    SendKeys "{Tab}"
                End If
            Case 5
                If rsPayment!cType = "CSH" Then
                    dtgPayment.Columns(5).Text = ""
                Else
                    dtgPayment.Columns(5).Text = Format(Date, "MM/dd/yyyy")
                End If
                SendKeys "{Tab}"
            Case 7
                dtgPayment_AfterColUpdate 7
'                If Trim(dtgPayment.Columns(7).Text) = "" Then
'                    MsgBox "Amount  is required."
'                    dtgPayment.Col = 7
'                    Exit Sub
'                Else
'                    SendKeys "{Tab}"
'                End If
                TBNewLine
                dtgPayment.Col = 0
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        KeyAscii = Asc(UCase(Chr(KeyAscii))) 'All Upper Case String
    End If
End Sub

Private Sub dtgPayment_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgPayment.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

'Private Sub dtgList_HeadClick(ByVal ColIndex As Integer)
'    SortGrid dtgList, ColIndex, rsHeader
'End Sub

'After column update
Private Sub dtgSI_AfterColUpdate(ByVal ColIndex As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 0
            If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgSI.Columns(0).Value) & "'") <> "" Then
                GetInitialItemValues
                dtgSI_ButtonClick 1
                dtgSI.Col = 2
                dtgSI.Columns(3).Value = rsDetail!nQty
            Else
                dtgSI_ButtonClick 0
            End If
        Case 3
            ComputeNet
            ComputeAmount
            ComputeTotal
        Case 4
            ComputeNet
            ComputeAmount
            ComputeTotal
        Case 5
            ComputeNet
            If Not lNetOK Then Exit Sub
            ComputeAmount
            ComputeTotal
        Case 6
            If Right(Trim(dtgSI.Columns(6).Text), 1) = "-" Then
                dtgSI.Columns(6).Text = Mid(Trim(dtgSI.Columns(6).Text), 1, Len(Trim(dtgSI.Columns(6).Text)) - 1)
                lLessAmount = False
            End If
            ComputeNet
            ComputeAmount
            ComputeTotal
        Case 7
             If rsPayment!nCash > nAmount Then
                rsPayment!nChange = rsPayment!nCash - nAmount
                rsPayment!nAmount = nAmount
            Else
                rsPayment!nChange = 0
                rsPayment!nAmount = rsPayment!nCash
            End If
    End Select
End Sub

Private Sub dtgSI_ButtonClick(ByVal ColIndex As Integer)
    If ColIndex = 1 Then
        If Mode <> Find Then
            Call MoveText(txtLongDesc, dtgSI, dtgSI.Columns(1))
            txtLongDesc = rsDetail!cLongDesc & ""
        End If
    End If
    If Mode <> AddNewEdit Then Exit Sub
    Select Case ColIndex
        Case 0
            If lPickListActive Then Exit Sub
            sFilterString = Trim(dtgSI.Columns(0).Text)
            frmITGPicker.zType = QProduct
            frmITGPicker.Show vbModal
            rsDetail!cItemNo = Trim(frmITGPicker.zCode) & "" 'GetValueFrTable("cItemNo", "ITEM", "cPartNo = '" & Trim(frmITGPickList.mCode) & "' ")
            rsDetail!cBarcodeID = IIf(Trim(frmITGPicker.zPart) = "", Null, "")
            dtgSI.Columns(9).Value = rsDetail!cBarcodeID 'Trim(frmITGPickList.mCode) & ""
            If (Trim(frmITGPicker.zName) & "") <> "" Then
                dtgSI.Col = 2
                GetInitialItemValues
                dtgSI.Columns(3).Value = rsDetail!nQty
            End If
        Case 2
            If Trim(dtgSI.Columns(0).Text) = "" Then Exit Sub
            Call LoadUnitValues(cboSI, Trim(dtgSI.Columns(0).Text))
            Call MoveCombo(cboSI, dtgSI, dtgSI.Columns(2))
            ComboLoadValue cboSI, Trim(dtgSI.Columns(2).Text)
        Case 4
            Call LoadComboValues(cboSI, "cValue", "PARAMETER_SYSTEM", "WHERE cType = 'PRICING' and nOrder in (1,10,9,8)", "nOrder")
            Call MoveCombo(cboSI, dtgSI, dtgSI.Columns(4))
            ComboLoadValue cboSI, Trim(dtgSI.Columns(4).Text)
        Case 5
            If lPickListActive Then Exit Sub
            frmITGPickList.mType = SRP
            cString = Trim(rsDetail!cItemNo)
            frmITGPickList.Show vbModal
            If Trim(frmITGPickList.mName) <> "" Then dtgSI.Columns(5).Value = CDbl(frmITGPickList.mCode)
            ComputeNet
            If Not lNetOK Then Exit Sub
            ComputeAmount
            ComputeTotal
    End Select
End Sub

Private Sub dtgSI_Click()
    If Mode = AddNewEdit Then dtgName = dtgSI.Name
End Sub

Private Sub dtgSI_Error(ByVal DataError As Integer, Response As Integer)
    Response = 0
End Sub

Private Sub dtgSI_KeyDown(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If (Shift = vbCtrlMask And KeyCode = 45) Then
        TBNewLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 46) Then
        TBDeleteLine
    ElseIf (Shift = vbCtrlMask And KeyCode = 83) Then
        TBSave
    ElseIf (Shift = vbCtrlMask And KeyCode = vbKeyTab) Then
        dtgPayment.SetFocus
    End If
End Sub

Private Sub dtgSI_KeyPress(KeyAscii As Integer)
    
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
        
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    
    If KeyAscii = 13 Then
        Select Case dtgSI.Col
            Case 0
                If GetValueFrTable("cItemNo", "ITEM", "cItemNo = '" & Trim(dtgSI.Columns(0).Value) & "'") = "" Then
                    dtgSI_ButtonClick (0) 'use button click
                End If
            Case 1
            
            Case 2
                If cboSI.Visible = False Then
                    dtgSI_ButtonClick (2)
                    If Trim(dtgSI.Columns(2).Text) <> "" Then cboSI = Trim(dtgSI.Columns(2).Text)
                Else
                    SendKeys "{Tab}"
                End If
            Case 4
                If cboSI.Visible = False Then
                    dtgSI_ButtonClick (4)
                    If Trim(dtgSI.Columns(4).Text) <> "" Then cboSI = Trim(dtgSI.Columns(4).Text)
                Else
                    SendKeys "{Tab}"
                End If
            Case 6
                rsDetail!cDiscount = dtgSI.Columns(6).Text
                dtgSI_AfterColUpdate (6)
                'dtgSI.Col = 10
                'dtgSI.Columns(10).Value = rsDetail!cStatus
                If Not lNetOK Then
                    dtgSI.Col = 6
                    dtgSI.Columns(6).Value = rsDetail!cDiscount
                    Exit Sub
                Else
                    TBNewLine
                    dtgSI.LeftCol = 0
                End If
            Case Else
                SendKeys "{Tab}"
        End Select
    Else
        Select Case dtgSI.Col
            Case 6
                '"-" character
                If (KeyAscii = 45) And lLessAmount Then
                    KeyAscii = 0
                ElseIf KeyAscii = 45 Then
                    lLessAmount = True
                End If

                '"/" character
                If (KeyAscii = 47) And lLessPercent Then
                    KeyAscii = 0
                ElseIf KeyAscii = 47 Then
                    lLessPercent = True
                    lLessAmount = False
                Else
                    lLessPercent = False
                End If
               
                KeyAscii = ValidKeys(KeyAscii, "-/1234567890.", True)
            Case Else
                KeyAscii = Asc(UCase(Chr(KeyAscii))) 'All Upper Case String
        End Select
    End If
    
End Sub

Private Sub dtgSI_KeyUp(KeyCode As Integer, Shift As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If rsDetail.RecordCount = 0 Then Exit Sub
    Select Case dtgSI.Col
        Case 6
            If Trim(dtgSI.Columns(6).Text) = "/" Then
                dtgSI.Columns(6).Text = ""
                lLessPercent = False
            End If
    End Select
End Sub

'Right click menu popup
Private Sub dtgSI_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
    If Mode <> AddNewEdit Then Exit Sub
    If Button = 2 Then
        dtgName = dtgSI.Name
        PopupMenu ITGLedgerMain.mnuDetail
    End If
End Sub

Private Sub Form_KeyUp(KeyCode As Integer, Shift As Integer)
Dim iKey As Integer
    iKey = ToolbarIndex(KeyCode, Shift)
    If iKey <> 0 Then
        If ITGLedgerMain.tbrMain.Buttons(iKey).Enabled = True Then
            ToolbarFunction iKey
        End If
    End If
End Sub

'Set Your Object
Private Sub Form_Load()
    
    'AcessBit Me, GetValueFrTable("AccessLevel", "SEC_ACCESSLEVEL", "RoleID = '" & SecUserRole & "' AND [Module] = 'OBSIVS'")
    
    Set FrmName = Me
    FormSetup
    
    lACNew = True
    lACEdit = True
    lACDelete = True
    lACPost = True
    lACCancel = True
    lACPrint = True

    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    
    
    'Load combobox values
    Call LoadComboValues(cboTerms, "cParamName", "PARAMETER_USER", "WHERE cType = 'TERMS' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    Call LoadComboValues(cboIntTerms, "cParamName", "PARAMETER_USER", "WHERE cType = 'TERMS' AND cCompanyID = '" & Trim(COID) & "'", "nOrder")
    Call LoadComboValues(cboPaymentType, "cValue", "PARAMETER_SYSTEM", "WHERE cType = 'SOPAYTYPE'")
    Call LoadComboValues(cboVatType, "cValue", "PARAMETER_USER", "WHERE cType = 'TAXTYPE'", "nOrder")

    FormLocking True
    FormSearch True
    SearchObj True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True

    Mode = Find
    txtInvNo.Locked = False
    
    lNetOK = True 'Boolean variable for discount computation
        
End Sub

'Activate your Toolbar Mode
Private Sub Form_Activate()
    TBBitReload
End Sub

'Release your Object
Private Sub Form_Unload(Cancel As Integer)
On Error Resume Next
    If Mode = AddNewEdit Then
        MsgBox "Unable to close. You are in Add/New/Edit mode." & vbCr & _
            " Must Save or Undo", vbCritical, Me.Caption
        Cancel = True
        Exit Sub
    End If
    
    CloseMenuTab ITGLedgerMain

    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , , , , , , , True
    BitVisible ITGLedgerMain.tbrMain
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = False
    
    
    
    
    
    Set oPrint = Nothing
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set rsPayment = Nothing
    Set connHeader = Nothing
    Set connDetail = Nothing
    Set connPayment = Nothing
    
    Set frmARCashSales = Nothing

    lCloseWindow = True
    
End Sub

'Add new record to the recordset
Public Sub TBNew()
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    txtInvNo.BackColor = &HE0FFFF
    Mode = AddNewEdit
    
    If rsHeader.State <> adStateOpen Then
        OpenNewConnection connHeader
        OpenNewConnection connDetail
        OpenNewConnection connPayment
        Set rsHeader = Nothing
        Set rsDetail = Nothing
        Set rsPayment = Nothing
        Set rsHeader = New ADODB.Recordset
        Set rsDetail = New ADODB.Recordset
        Set rsPayment = New ADODB.Recordset
        OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, "WHERE 1 = 0"
        OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, "WHERE 1 = 0"
        OpenRecordsetWithCN rsPayment, "*", "SALES_P", connPayment, "WHERE 1 = 0"
        SetDataSource
        SetDataField
    Else
        vBM = rsHeader.Bookmark
    End If
    
    rsHeader.AddNew
    rsHeader!cCompanyID = COID
    rsHeader!dDate = Date
    rsHeader!cType = "Van Selling"
    rsHeader!cPayType = "Cash"
    
    txtWH = ""
    
    txtReturns = "0.00"
    txtCredit = "0.00"
    txtDebit = "0.00"
    txtPayment = "0.00"
    txtBalance = "0.00"

    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    SSTab1.ActiveTab = 0
    txtInvNo.SetFocus

End Sub

'Undo all changes to the recordset
Public Sub TBUndoAll()
On Error GoTo ErrorHandler

    Mode = Normal
    
    If rsHeader.Status = adRecNew Then TBUndoCurrent
    
    rsHeader.CancelBatch adAffectAll
    rsDetail.CancelBatch adAffectAll
    rsPayment.CancelBatch adAffectAll
    
    
    UnbindControls
    
    If rsHeader.RecordCount <> 0 Then rsHeader.Bookmark = vBM
    
    Set FrmName = Me
    FormLocking True
    
    If rsHeader.RecordCount <> 0 Then
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
    Else
        RSZero
        Mode = Find
    End If

    sbRS.Panels(2) = ""

    SetDataSource
    SetDataField

ErrorHandler:
    cboSI.Visible = False
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoAll
    End If

End Sub

'Undo changes on the current record
Public Sub TBUndoCurrent()
On Error GoTo ErrorHandler

    GetChild
    If rsHeader.Status = adRecNew Then
        rsDetail.CancelBatch adAffectAll
        rsHeader.CancelUpdate
    Else
        rsHeader.CancelBatch adAffectCurrent
        rsDetail.CancelBatch adAffectAll
    End If
   
    If rsHeader.RecordCount = 0 Then RSZero

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217842 Then 'Operation was cancelled. (Error returned by ITGDateBox)
        TBUndoCurrent
    End If

End Sub

'Save all changes
Public Sub TBSave()
Dim OKUpdate As Boolean
Dim lNew As Boolean
On Error GoTo ErrHandler

    'Audit Trail
    lBoolean = False
    If rsHeader.Status = adRecNew Then
        lBoolean = True
            
    End If
    
'    If rsPayment.RecordCount <> 0 Then rsPayment.MoveFirst
'        Do Until rsPayment.EOF
'            rsPayment!cInvNo = strNo
'            rsPayment.MoveNext
'        Loop
    If nCash < nAmount Then
        MsgBox nCash & " payment is not applicable to invoice amount " & nAmount & ".", vbInformation + vbCritical, "iTG Finance Manager"
        Exit Sub
    End If

    If Not MandatoryOK Then Exit Sub
    
    If nCash <> nAmount Then
        If MsgBox("The amount received is not equal to invoice amount. Do you want to continue?", vbYesNo, "iTG Finance Manager") = vbNo Then
            Exit Sub
        End If
    End If
    If rsPayment.EOF = False Then
    If rsPayment!cType = "CSH" Then
        rsPayment!cAuthorization = ""
        rsPayment!cCCardType = ""
        rsPayment!cCCardNo = ""
        rsPayment!dExpiration = Null
    End If
    End If
    'Discount validation
    ComputeNet
    If Not lNetOK Then
        dtgSI.SetFocus
        Exit Sub
    End If
    ComputeAmount
    ComputeTotal
   
    OKUpdate = False
    cn.BeginTrans
    connHeader.BeginTrans
    connDetail.BeginTrans
    connPayment.BeginTrans

    rsHeader.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    rsPayment.UpdateBatch adAffectAll

    cn.CommitTrans
    connPayment.CommitTrans
    connDetail.CommitTrans
    connHeader.CommitTrans
    If rsPayment.EOF = False Then
        Call SalesReciept
        Call SaveCreditCard
    End If
    OKUpdate = True
    
    Set FrmName = Me
    FormLocking True
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
    Mode = Normal
        
    TotalAmount
    
    If nCash > nAmount Then
'        MsgBox "Change is " & (nCash - nAmount) & ".", vbInformation, "iTG Finance Manager"
        frmPrompt.LoadPrompt "Change:", (nCash - nAmount), "&OK", "Cash Sales - Change"
    End If
    
    MsgBox "Record/s successfully saved.", vbInformation, "iTG Finance Manager"
    sbRS.Panels(2) = ""

    'Audit trail
    UpdateLogFile "Sales Invoice-VS", Trim(txtInvNo), IIf(lBoolean, "Inserted", "Updated")
    
    'Update GL Activity
    UpdateGLA "Update", "SI", Trim(txtInvNo)

ErrHandler:
    cboSI.Visible = False
    cboCS_C.Visible = False
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        OKUpdate = True
        cn.RollbackTrans
        connPayment.RollbackTrans
        connDetail.RollbackTrans
        connHeader.RollbackTrans
        MsgBox "Record cannot be updated. Some values may have been changed by other user/s since last read." & vbCr & _
                "Records will be automatically refreshed. All changes made to the record will be gone upon refresh.", vbInformation, "iTG Finance Manager"
        vBookMark = rsHeader.Bookmark
        UnbindControls
        rsHeader.Requery
        rsDetail.Requery
        rsPayment.Requery
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True
        Mode = Normal
        If rsHeader.RecordCount <> 0 Then
            Set FrmName = Me
            FormLocking True
            SetDataField
            SetDataSource
            rsHeader.Bookmark = vBookMark
        Else
            RSZero
        End If
    End If
    If Not OKUpdate Then
        MsgBox "Transaction update failed.", vbInformation, "iTG Finance Manager"
        cn.RollbackTrans
        connPayment.RollbackTrans
        connDetail.RollbackTrans
        connHeader.RollbackTrans
        ErrorLog err.Number, err.Description, Me.Name 'Error log
    End If
    
End Sub

'Sets the form & recorset to add/edit mode
Public Sub TBEdit()
    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Edit is not allowed.", vbExclamation, "iTG Finance Manager"
        Exit Sub
    End If
    If Not AllowEdit Then Exit Sub
    Mode = AddNewEdit
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    Set FrmName = Me
    FormLocking False
    ClrRequired &HC0&
    txtGross.Locked = True
    txtInvNo.Locked = True
    SSTab1.ActiveTab = 0
    dtbDate.SetFocus
    vBM = rsHeader.Bookmark
End Sub

'Delete record
Public Sub TBDelete()
On Error GoTo ErrorHandler

    sID = Trim(txtInvNo)
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled. Deletion is not allowed.", vbExclamation, "iTG Finance Manager"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to delete this record?", vbQuestion + vbYesNo, "iTG Finance Manager") = vbNo Then Exit Sub

    If Not AllowDelete("delete") Then Exit Sub
    
    'Update GL Activity
    UpdateGLA "Delete", "SI", Trim(txtInvNo)
    
    GetChild
    If rsDetail.RecordCount <> 0 Then
        rsDetail.MoveFirst
        Do Until rsDetail.RecordCount = 0
            rsDetail.Delete adAffectCurrent
            If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
        Loop
    End If
    
    If rsPayment.RecordCount <> 0 Then
        rsPayment.MoveFirst
        Do Until rsPayment.RecordCount = 0
            rsPayment.Delete adAffectCurrent
            If rsPayment.RecordCount <> 0 Then rsPayment.MoveFirst
        Loop
    End If
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), "Deleted"

    rsHeader.Delete adAffectCurrent
    
    rsPayment.UpdateBatch adAffectAll
    rsDetail.UpdateBatch adAffectAll
    rsHeader.UpdateBatch adAffectAll
    
    cn.Execute ("DELETE PR WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE PR_T WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE PR_C WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE PR_MAP WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
        
    TBPrevRec

    Mode = Normal

    If rsHeader.RecordCount = 0 Then
        RSZero
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    ElseIf err.Number = -2147217864 Then
        cn.Execute "DELETE SALES_P WHERE cInvNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE SALES_T WHERE cInvNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        cn.Execute "DELETE SALES WHERE cInvNo = '" & sID & "' AND cCompanyID = '" & COID & "'"
        Resume Next
    End If

End Sub

'Search using the frmITGSearch
Public Sub TBFind()
    Mode = Normal
    txtInvNo.Locked = True
    frmITGSearch.Show vbModal
End Sub

'Search using the recordset primary key
Public Sub TBFindPrimary()
Dim sTemp As String
If Mode = Find Then
    FormWaitShow App.Path & "\Transmit.avi", "Loading data . . ."
        
    OpenNewConnection connHeader
    OpenNewConnection connDetail
    OpenNewConnection connPayment
    
    Set rsHeader = Nothing
    Set rsDetail = Nothing
    Set rsPayment = Nothing
    Set rsHeader = New ADODB.Recordset
    Set rsDetail = New ADODB.Recordset
    Set rsPayment = New ADODB.Recordset
            
    sTemp = Trim$(GetSearchString)
    If sTemp = "ERROR" Then
        MsgBox "Only Allows A - Z, 0 - 9, '.', ',' and %(wildcard)", vbExclamation, ""
        BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
        txtInvNo.Locked = False
        txtInvNo.SetFocus
        Exit Sub
    End If
    
    OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, IIf(sTemp = "", "", " WHERE " & sTemp)
    'OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail
         
    OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, IIf(sTemp = "", "", " WHERE cInvNo IN (SELECT cInvNo FROM SALES WHERE " & sTemp & ")")
    
    OpenRecordsetWithCN rsPayment, "*", "SALES_P", connPayment, IIf(sTemp = "", "", " WHERE cInvNo IN (SELECT cInvNo FROM SALES WHERE " & sTemp & ")")
                    
    Set FrmName = Me
    FormLocking True
            
       If rsHeader.RecordCount = 0 Then
        FormWaitHide
        MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
        RSZero
        FormSearch True
        SearchObj True
        Mode = Find
        Exit Sub
    End If
    SetDataSource
    SetDataField
    txtInvNo.BackColor = &HE0FFFF
    Mode = Normal
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , lACCancel, , , True, True, lACPrint, True, True

    FormWaitHide
Else
    RSZero
    FormSearch True
    SearchObj True
    Mode = Find
    
   
End If

End Sub

'Reload menu buttons (do not delete this sub)
Public Sub TBBitReload()
    BitVisible ITGLedgerMain.tbrMain, True, True
    ITGLedgerMain.tbrMain.Buttons("btnFind").ButtonMenus("btnFindP").Enabled = True
    BitReload ITGLedgerMain, Me, ITGLedgerMain.tbrMain, sBit
    Set FrmName = Me
    dtgName = dtgSI.Name
End Sub

'Close active window
Public Sub TBCloseWindow()
    Unload Me
End Sub

'Move first
Public Sub TBFirstRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveFirst rsHeader
    
End Sub

'Move previuos
Public Sub TBPrevRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MovePrevious rsHeader
    
End Sub

'Move next
Public Sub TBNextRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveNext rsHeader
    
End Sub

'Move last
Public Sub TBLastRec()
    If rsHeader.State <> adStateOpen Then Exit Sub
    MoveLast rsHeader
    
End Sub

'Add new line to the detail recordset
Public Sub TBNewLine()
    
    If rsHeader!cInvNo = "" Then Exit Sub
'    If Trim(txtWHName) = "" Then
'        MsgBox "Van/Warehouse is mandatory.", vbInformation, "iTG Finance Manager"
'        txtWH.SetFocus
'        Exit Sub
'    End If
    
    If dtgName = "dtgSI" Then
        rsDetail.AddNew
        rsDetail!cCompanyID = COID
        rsDetail!cInvNo = Trim(rsHeader!cInvNo)
        rsDetail!cWH = Trim(txtWH)
        dtgSI.Col = 0
        GetChild
        If rsDetail.RecordCount <> 0 Then rsDetail.MoveLast
        dtgSI.Col = 0
        dtgSI.Columns(0).Value = ""
        dtgSI.SetFocus
    ElseIf dtgName = "dtgPayment" Then
        TotalAmount
        dtgPayment_AfterColUpdate 7
        If nAmount = nPAmount Then Exit Sub
        If rsDetail.RecordCount <= 0 Then
            MsgBox "Detail(s) of this invoice is mandatory.", vbCritical, "ComUnion"
            dtgSI.SetFocus
            Exit Sub
        End If
        rsPayment.AddNew
        rsPayment!cCompanyID = COID
        rsPayment!cInvNo = Trim(txtInvNo.Text)
        rsPayment!dDate = Trim(dtbDate.Text)
        dtgPayment.Col = 0
        GetChild
        If rsPayment.RecordCount <> 0 Then rsPayment.MoveLast
        dtgPayment.Col = 0
        dtgPayment.Columns(0).Value = ""
        dtgPayment.SetFocus
    End If
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True

End Sub

'Delete line in the detail recordset
Public Sub TBDeleteLine()
On Error GoTo ErrorHandler
    
    If dtgName = "dtgSI" Then
        If rsDetail.RecordCount = 0 Then Exit Sub
        vBookMark = dtgSI.Bookmark
        GetChild
        dtgSI.Bookmark = vBookMark
        rsDetail.Delete adAffectCurrent
        ComputeTotal
    ElseIf dtgName = "dtgPayment" Then
        If rsPayment.RecordCount = 0 Then Exit Sub
        vBookMark = dtgPayment.Bookmark
        GetChild
        dtgPayment.Bookmark = vBookMark
        rsPayment.Delete adAffectCurrent
    End If
    GetChild
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, , , , True, True, , , True, True, , , , True
    
ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo All
Public Sub TBUndoLineAll()
On Error GoTo ErrorHandler

    If dtgName = "dtgSI" Then
        rsDetail.CancelBatch adAffectAll
    ElseIf dtgName = "dtgPayment" Then
        rsDetail.CancelBatch adAffectAll
    End If

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Undo current line
Public Sub TBUndoLineCurrent()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Post current record
Public Sub TBPostRecord()
    MsgBox "Unavailable on " & Me.Name
End Sub

'Cancel current record
Public Sub TBCancelRecord()
On Error GoTo ErrorHandler
    
    If rsHeader.RecordCount = 0 Then Exit Sub

    If rsHeader!lCancelled = True Then
        MsgBox "Transaction was already cancelled.", vbExclamation, "iTG Finance Manager"
        Exit Sub
    End If
    
    If MsgBox("Are you sure you want to cancel this record?", vbQuestion + vbYesNo, "iTG Finance Manager") = vbNo Then Exit Sub

    If Not (AllowDelete("cancel")) Then Exit Sub
    
    'Audit trail
    UpdateLogFile "Sales Invoice", Trim(txtInvNo), "Cancelled"

    'Update GL Activity
    UpdateGLA "Delete", "SI", Trim(txtInvNo)
    
    cn.Execute ("UPDATE SALES SET lCancelled = 1 WHERE cInvNo = '" & Trim(txtInvNo) & "' AND cCompanyID = '" & COID & "'")
    
    sbRS.Panels(5) = "CANCELLED"
    Mode = Normal
    
    rsHeader!lCancelled = True
    rsHeader.UpdateBatch adAffectAll

ErrorHandler:
    If err.Number = -2147217885 Then
        Resume Next
    End If

End Sub

'Print
Public Sub TBPrintRecord()
    If Trim(txtInvNo) = "" Then Exit Sub
    RepName = "Sales_Invoice_Trans" ' GetValueFrTable("cParamName", "PARAMETER_USER", "cType = 'SIDOCTYPE' AND cValue = '" & Trim(cboDocType) & "'")
    cModule = "Sales_Invoice"
    oPrint.PrintReceipt Trim(txtInvNo)
End Sub

'Sets the data source of the controls
Sub SetDataSource()
    Set FrmName = Me
    BindControls rsHeader
    Set dtgList.DataSource = rsHeader
    Set dtgSI.DataSource = rsDetail
    Set txtLongDesc.DataSource = rsDetail
    Set dtgPayment.DataSource = rsPayment
      
End Sub
    
'Sets the data field for every bounded controls
Sub SetDataField()
    With rsHeader
        txtInvNo.DataField = !cInvNo
        dtbDate.DataField = !dDate
        txtCode.DataField = !cCode
        txtMSCode.DataField = !cMSCode
        txtPDCode.DataField = !cPDCode
        txtSMCode.DataField = !cSMan
        txtPCCode.DataField = !cPCCode
        txtRemarks.DataField = !cRemarks
        txtIntTerms.DataField = !cIntTerm
        txtTerms.DataField = !cTerm
        txtPaymentType.DataField = !cPayType
        txtGross.DataField = !nGross
        txtVatType.DataField = !cVatType
    End With
End Sub

Private Sub rsHeader_MoveComplete(ByVal adReason As ADODB.EventReasonEnum, ByVal pError As ADODB.Error, adStatus As ADODB.EventStatusEnum, ByVal pRecordset As ADODB.Recordset)
On Error GoTo ErrorHandler
    
    If Not (rsHeader.EOF) Or Not (rsHeader.BOF) Then
        'Status bar setup
        sbRS.Panels(1) = "Record: " & IIf((rsHeader.AbsolutePosition = -2), "0", rsHeader.AbsolutePosition) & "/" & rsHeader.RecordCount
        
        If rsHeader.Status <> adRecNew Then
            txtInvNo.Locked = True
        Else
            txtInvNo.Locked = False
        End If
        
        If Mode = AddNewEdit Then
            Select Case rsHeader.Status
                Case adRecNew
                    sbRS.Panels(2) = "New"
                Case adRecModified
                    sbRS.Panels(2) = "Modified"
                Case Else
                    sbRS.Panels(2) = ""
            End Select
        Else
            sbRS.Panels(2) = ""
        End If
        
        GetChild
        ShowInvoiceBalance
    
        If rsHeader!lCancelled = True Then
            sbRS.Panels(4) = rsHeader!cCRemarks
            sbRS.Panels(5) = "CANCELLED"
        Else
            sbRS.Panels(4) = ""
            sbRS.Panels(5) = ""
        End If
    
        txtWH = Trim(rsDetail!cWH) & ""
        
    Else
        sbRS.Panels(1) = "Record: 0/0"
        sbRS.Panels(2) = ""
        txtInvNo.Locked = False
    End If
    
    If Mode = AddNewEdit Then
        dtgSI.Refresh
    End If
    
ErrorHandler:
    'Err.Number -2147217885
    'Description - Row handle referred to a deleted row or a row marked for deletion.
    If err.Number = -2147217885 Then
        Resume Next
    End If
    
End Sub

Private Sub Timer1_Timer()
    If Mode = AddNewEdit Then
        SSTab1.TabEnabled(1) = False
    Else
        SSTab1.TabEnabled(1) = True
    End If
End Sub

Private Sub txtCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtName) = "" And Trim(txtCode) <> "" Then cmdPickCode_Click
End Sub

Private Sub txtLongDesc_KeyPress(KeyAscii As Integer)
    If Mode <> AddNewEdit Then Exit Sub
    If KeyAscii = 39 Then KeyAscii = 0 'Apostrophe {'}
    KeyAscii = Asc(UCase(Chr(KeyAscii)))
End Sub

Private Sub txtLongDesc_LostFocus()
    txtLongDesc.Visible = False
    dtgSI.Col = 2
    dtgSI.SetFocus
End Sub

Private Sub txtMSCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtMSDesc) = "" And Trim(txtMSCode) <> "" Then cmdPickMS_Click
End Sub

Private Sub txtPaymentType_Change()
    If Trim(txtPaymentType) <> "" Or txtPaymentType <> vbNullString Then
        cboPaymentType = Trim(txtPaymentType)
    Else
        cboPaymentType.ListIndex = -1
    End If
End Sub

Private Sub txtPCCode_Change()
    txtPCDesc = ""
    txtPCDesc = GetValueFrTable("cDescription", "PROFITCENTER", "cPCCode = '" & Trim(txtPCCode) & "'")
End Sub

Private Sub txtPCCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtPCDesc) = "" And Trim(txtPCCode) <> "" Then cmdPickPC_Click
End Sub

Private Sub txtSMCode_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtSMName) = "" And Trim(txtSMCode) <> "" Then cmdPickSM_Click
End Sub

Private Sub txtInvNo_LostFocus()
    'Does Code Already exists
    If Mode = AddNewEdit Then
        If Trim(txtInvNo) = "" Then
            MsgBox "Empty primary input.", vbInformation, "iTG Finance Manager"
            PreviousTab frmComUnionMenuTab
            txtInvNo.SetFocus
        Else
            If rsHeader.Status <> adRecNew Then Exit Sub
            txtInvNo = Trim(txtInvNo)
            If IDExisting(rsHeader, "cInvNo", "SALES", Trim(rsHeader!cInvNo)) Then
                MsgBox "Sales Invoice No. already exists.", vbInformation, "iTG Finance Manager"
                PreviousTab frmComUnionMenuTab
                txtInvNo.SetFocus
            End If
        End If
    End If
End Sub

Private Sub txtCode_Change()
    txtName = ""
    txtName = GetValueFrTable("cName", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtName) <> "" Then
        rsHeader!cMSCode = GetValueFrTable("cMSCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cPDCode = GetValueFrTable("cPDCode", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cTerm = GetValueFrTable("cTerm", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        rsHeader!cIntTerm = GetValueFrTable("cIntTerm", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        txtWH.Text = GetValueFrTable("cWH", "WHSE", "cSMan = '" & Trim(rsHeader!cSMan) & "' ")
        If GetValueFrTable("lBit", "SYSTEM_OPTION", "cCode = 'CLNT_MAN_USERDFSMAN'") = True Then
            GetUser txtSMCode, txtSMName
        Else
            rsHeader!cSMan = GetValueFrTable("cSMan", "CLIENT_CUSTOMER", "cCode = '" & Trim(txtCode) & "'")
        End If
    Else
        txtMSCode = ""
        txtPDCode = ""
        txtSMCode = ""
        cboTerms.ListIndex = -1
        cboIntTerms.ListIndex = -1
    End If
End Sub

Private Sub txtIntTerms_Change()
    If Trim(txtIntTerms) <> "" Or txtIntTerms <> vbNullString Then
        cboIntTerms = Trim(txtIntTerms)
    Else
        cboIntTerms.ListIndex = -1
    End If
End Sub

Private Sub txtMSCode_Change()
    txtMSDesc = ""
    txtMSDesc = GetValueFrTable("cDescription", "CLASSIFICATION", "cClassCode = '" & Trim(txtMSCode) & "' AND cType = 'MS'")
End Sub

Private Sub txtSMCode_Change()
    txtSMName = ""
    txtSMName = GetValueFrTable("cName", "SALESMAN", "cCode = '" & Trim(txtSMCode) & "'")
End Sub

Private Sub txtTerms_Change()
    If Trim(txtTerms) <> "" Or txtTerms <> vbNullString Then
        cboTerms = Trim(txtTerms)
    Else
        cboTerms.ListIndex = -1
    End If
End Sub

'Check if all mandatory fields are complete
Function MandatoryOK() As Boolean
    
    MandatoryOK = True

    If Trim(txtInvNo) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Invoice Number' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        txtInvNo.SetFocus
        Exit Function
    End If
    
    If rsHeader.Status = adRecNew Then
        If IDExisting(rsHeader, "cInvNo", "SALES", Trim(rsHeader!cInvNo)) Then
            MandatoryOK = False
            MsgBox "Sales invoice No. already exist.", vbInformation, "iTG Finance Manager"
            txtInvNo.SetFocus
            Exit Function
        End If
    End If

    'Required fields
    If Trim(dtbDate.Text) = "__/__/____" Then
        MandatoryOK = False
        MsgBox "Field 'Transaction Date' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        dtbDate.SetFocus
        Exit Function
    ElseIf Trim(txtCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Customer' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        txtCode.SetFocus
        Exit Function
    ElseIf Trim(txtMSCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Market Segment' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        txtMSCode.SetFocus
        Exit Function
    ElseIf Trim(txtSMCode) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Salesman' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        txtSMCode.SetFocus
        Exit Function
    ElseIf Trim(txtIntTerms) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Internal Terms' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        cboIntTerms.SetFocus
        Exit Function
    ElseIf Trim(txtTerms) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Actual Terms' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        cboTerms.SetFocus
        Exit Function
    ElseIf Trim(txtPaymentType) = "" Then
        MandatoryOK = False
        MsgBox "Field 'Payment Type' is mandatory. Null value is not allowed.", vbInformation, "iTG Finance Manager"
        cboPaymentType.SetFocus
        Exit Function
    End If
    
    GetChild
    
    'Transaction without details
    If rsDetail.RecordCount = 0 Then
        MandatoryOK = False
        MsgBox "Cannot save transaction without details.", vbInformation, "iTG Finance Manager"
        dtgSI.SetFocus
        Exit Function
    End If
    
    If rsDetail.RecordCount <> 0 Then rsDetail.MoveFirst
    Do Until rsDetail.EOF
        If rsDetail.Status = (adRecNew) Or rsDetail.Status = (adRecModified) Then
            If IsNull(rsDetail!cItemNo) Then
                rsDetail.Delete
            ElseIf Trim(rsDetail!cItemNo) = "" Then
                rsDetail.Delete
            Else
                rsDetail.MoveNext
            End If
        Else
            rsDetail.MoveNext
        End If
    Loop
    
    If rsPayment.RecordCount <> 0 Then rsPayment.MoveFirst
    Do Until rsPayment.EOF
        If rsPayment.Status = (adRecNew) Or rsPayment.Status = (adRecModified) Then
            If IsNull(rsPayment!cType) Then
                rsPayment.Delete
            ElseIf Trim(rsPayment!cType) = "" Then
                rsPayment.Delete
            Else
                rsPayment.MoveNext
            End If
            
            If IsNull(rsPayment!nCash) Then
                rsPayment.Delete
'            ElseIf Trim(rsPayment!nCash) = "" Then
'                rsPayment.Delete
'            Else
'                rsPayment.MoveNext
            End If
        Else
            rsPayment.MoveNext
        End If
    Loop
    GetChild

    If rsDetail.RecordCount < 1 Then
        MsgBox "Cannot save transaction without details.", vbExclamation, "iTG Finance Manager"
        MandatoryOK = False
        Exit Function
    End If

End Function

'Filter detail recordset to header's primary
Private Sub GetChild()
    rsDetail.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"
    rsPayment.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"
End Sub

'Sets the form if record number is zero
Private Sub RSZero()
    sbRS.Panels(1) = "Record: 0/0"
    sbRS.Panels(2) = ""
    sbRS.Panels(4) = ""
    sbRS.Panels(5) = ""
    
    Set dtgSI.DataSource = Nothing
    dtgSI.Refresh
    
    Set dtgPayment.DataSource = Nothing
    dtgPayment.Refresh
    
    Set FrmName = Me
    UnbindControls
    TextClearing
    FormLocking True
    
    If rsHeader.State = adStateOpen Then rsHeader.Close
    If rsDetail.State = adStateOpen Then rsDetail.Close
    
    BitEnabled ITGLedgerMain, Me, ITGLedgerMain.tbrMain, lACNew, , , , , , , , , True, , , True
    
    txtInvNo.Locked = False
    txtInvNo.SetFocus
    
    Mode = Find
End Sub

Sub SearchObj(lEnable As Boolean)
    dtbDate.Enabled = lEnable
    cmdPickCode.Enabled = lEnable
    cmdPickMS.Enabled = lEnable
    cmdPickPD.Enabled = lEnable
    cmdPickSM.Enabled = lEnable
    cboIntTerms.Enabled = lEnable
    cboTerms.Enabled = lEnable
    cboPaymentType.Enabled = lEnable
    cboVatType.Enabled = lEnable
End Sub

' mae 05.06.04
'Gets initital item values
Private Sub GetInitialItemValues()
    rsDetail!cDesc = Trim(GetValueFrTable("cDesc", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
    rsDetail!cUnit = Trim(GetValueFrTable("cUnit", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
    rsDetail!nUDPrice = Trim(GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'")) & ""
    GetCustFromPM
'    rsDetail!cPricing = "SRP"
    'rsDetail!cDiscount = Trim(GetValueFrTable("cDiscount ", "ITEM A LEFT OUTER JOIN CLIENT_PDDISCOUNT B " & _
    '        "ON A.cCompanyID = B.cCompanyID AND A.cPDCode = B.cPDCode AND A.cCompanyID = '" & COID & "' ", " A.cItemNo = '" & Trim(rsDetail!cItemNo) & "' " & _
    '        "AND B.cCode = '" & Trim(txtCode) & "' ", True)) & ""
    
    rsDetail!nAmount = 0
    rsDetail!nCost = IIf(GetValueFrTable("nAveCost", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'") = "", 0, GetValueFrTable("nAveCost", "ITEM", "cItemNo = '" & Trim(rsDetail!cItemNo) & "'"))
    rsDetail!cCosting = "Average"
                
    aQty(rsDetail.AbsolutePosition) = rsDetail!nQty
    rsDetail!nPrice = rsDetail!nUDPrice * rsDetail!nQty
    
    ComputeNet
    ComputeAmount
    ComputeTotal
    

End Sub

Private Function GetSearchString() As String
On Error GoTo ErrorHandler
Dim sWhere As String

    GetSearchString = True

    If Trim$(txtInvNo.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cInvNo LIKE '" & Trim$(txtInvNo.Text) & "%'"
    End If

    If Trim$(dtbDate.Text) <> "__/__/____" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " dDate = '" & Trim$(dtbDate.Text) & "'"
    End If
    
    If Trim$(txtCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cCode LIKE '" & Trim$(txtCode.Text) & "%'"
    End If
    
    If Trim$(txtMSCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cMSCode LIKE '" & Trim$(txtMSCode.Text) & "%'"
    End If
    
    If Trim$(txtPDCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPDCode LIKE '" & Trim$(txtPDCode.Text) & "%'"
    End If
    
    If Trim$(txtSMCode.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cSMan LIKE '" & Trim$(txtSMCode.Text) & "%'"
    End If
    
    If Trim(txtIntTerms.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cIntTerm LIKE '" & Trim$(txtIntTerms.Text) & "%'"
    End If
    
    If Trim(txtTerms.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cTerm LIKE '" & Trim$(txtTerms.Text) & "%'"
    End If
    
    If Trim(txtPaymentType.Text) <> "" Then
        sWhere = sWhere & IIf(Trim$(sWhere) = "", "", " AND ") & " cPayType LIKE '" & Trim$(txtPaymentType.Text) & "%'"
    End If
    
    GetSearchString = Trim$(sWhere)

    Exit Function
ErrorHandler:
    GetSearchString = "ERROR"
End Function

'Computes multi-level discount
Private Sub ComputeNet()
Dim si, l As Integer
Dim s(0 To 15), ns, disc As String
Dim lStop As Boolean
Dim net As Double

On Error GoTo ErrHandler
    
    lNetOK = True
    
    If rsDetail.RecordCount = 0 Then Exit Sub
    If IsNull(rsDetail!cItemNo) Then Exit Sub
    If Trim(rsDetail!cItemNo) = "" Then Exit Sub
    
    lNetOK = False

    rsDetail!cDiscount = Trim(dtgSI.Columns(6).Text)
    disc = rsDetail!cDiscount
    net = dtgSI.Columns(5).Value 'rsDetail!nPrice  'dtgSI.Columns(5).Value
    
    If disc <> "" Then
        l = Len(disc)
        i = 1
        si = 0
        Do While Not i = l + 1
            cString = Mid(disc, i, 1)
            If cString <> "/" Then
                ns = ns + cString
                s(si) = ns
            Else
                si = si + 1
                ns = ""
            End If
            i = i + 1
        Loop
        
        si = 0
        lStop = False
        Do While Not lStop
            If s(si) <> "" Then
                If Right(s(si), 1) = "-" Then GoTo ErrHandler
                If (Mid(s(si), 1, 1) = "-") Then
                    net = net + CDbl(s(si))
                Else
                    net = net - (net * (CDbl(s(si)) * 0.01))
                End If
                si = si + 1
            Else
                lStop = True
            End If
        Loop
    
    End If
    
    If s(0) = "" Then dtgSI.Columns(6).Text = ""
    
    dtgSI.Columns(7).Value = Round(net, 4)
    
    lNetOK = True
    
ErrHandler:
    If Not lNetOK Then
        MsgBox "Invalid discount format! (ex: '10/5/-100', '-100/10/5', '10/-100/5')", vbCritical, "iTG Finance Manager"
        lLessAmount = False
        lLessPercent = False
    End If

End Sub

'Computes total amount per detail line
Private Sub ComputeAmount()
On Error Resume Next
Dim nAmount As Double
    If Mode <> AddNewEdit Then Exit Sub
    With dtgSI
        nAmount = IIf(IsNull(.Columns(7).Value), 0, .Columns(7).Value) * _
                    IIf(IsNull(.Columns(3).Value), 0, .Columns(3).Value)
        .Columns(8).Text = Format(nAmount, "###,##0.#0")
    End With
End Sub

'Computes total amount of order
Public Sub ComputeTotal()
Dim n As Double
    
On Error Resume Next
    
    If Mode <> AddNewEdit Then Exit Sub
    
    n = 0
    Set rs = New Recordset
    Set rs = rsDetail.Clone
    rs.Filter = "cInvNo = '" & Trim(rsHeader!cInvNo) & "'"

    rs.MoveFirst
    Do Until rs.EOF
        n = n + IIf(IsNull(rs!nAmount), 0, rs!nAmount)
        rs.MoveNext
    Loop
    Set rs = Nothing
    
   ' rsHeader!nGross = n
    rsHeader!nGross = n
    
End Sub

Private Function AllowEdit() As Boolean
    AllowEdit = True
    
    'Cannot edit if transaction already has a collection reference
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot edit transaction with collection.", vbCritical + vbExclamation, "iTG Finance Manager"
        AllowEdit = False
        Exit Function
    End If
    
End Function

Private Function AllowDelete(sAction As String) As Boolean
    AllowDelete = True
    
    'Cannot delete if transaction already has a collection reference
    If GetValueFrTable("cInvNo", "PR_T", "cInvNo = '" & Trim(rsHeader!cInvNo) & "'") <> "" Then
        MsgBox "Cannot " & sAction & " transaction with collection.", vbCritical + vbExclamation, "iTG Finance Manager"
        AllowDelete = False
        Exit Function
    End If
    
End Function

'Compute the Qty according to unit
Function GetActualUnitQty(OrigQty As Double, ItemNo As String, CurrentUnit As String) As Double
Dim nUnitQty As Double

    nUnitQty = GetValueFrTable("nFactor", "ITEM_UNIT", "cItemNo = '" & ItemNo & "' AND cUnit = '" & CurrentUnit & "'")
    
    If nUnitQty = 0 Then
        GetActualUnitQty = OrigQty
        nSRP(rsDetail.AbsolutePosition) = GetValueFrTable("nSRPrice", "ITEM", "cItemNo = '" & ItemNo & "' AND cUnit = '" & CurrentUnit & "'")
        nWSP(rsDetail.AbsolutePosition) = GetValueFrTable("nWSPrice", "ITEM", "cItemNo = '" & ItemNo & "' AND cUnit = '" & CurrentUnit & "'")
        nNewQtyBoundary(rsDetail.AbsolutePosition) = 0
    Else
        GetActualUnitQty = Fix(OrigQty / nUnitQty)
        nSRP(rsDetail.AbsolutePosition) = GetValueFrTable("nSRPrice", "ITEM_UNIT", "cItemNo = '" & ItemNo & "' AND cUnit = '" & CurrentUnit & "'")
        nWSP(rsDetail.AbsolutePosition) = GetValueFrTable("nWSPrice", "ITEM_UNIT", "cItemNo = '" & ItemNo & "' AND cUnit = '" & CurrentUnit & "'")
        nNewQtyBoundary(rsDetail.AbsolutePosition) = Fix(OrigQty / nUnitQty)
    End If
    
End Function

Private Sub txtVatType_Change()
If Trim(txtVatType) <> "" Or txtVatType <> vbNullString Then
        cboVatType = Trim(txtVatType)
    Else
        cboVatType.ListIndex = -1
    End If
End Sub

Private Sub txtWH_Change()
    txtWHName = ""
    txtWHName = GetValueFrTable("cName", "WHSE", "cWH = '" & Trim(txtWH) & "'")
End Sub

Private Sub txtWH_LostFocus()
    If Mode <> AddNewEdit Then Exit Sub
    If Trim(txtWH) = "" Then Exit Sub
    If GetValueFrTable("cWH", "WHSE", "cWH = '" & Trim(txtWH) & "'") = "" Then cmdPickWH_Click
End Sub

'Show the balances of each sales invoice
'Binding of the textboxex was disabled
Private Sub ShowInvoiceBalance()
Dim rsBalance As New Recordset

    If Mode = AddNewEdit Then Exit Sub
    
        sSQL = "SELECT *, ISNULL((nSales - nReturns - nPaid - nCredit + nDebit), 0) AS nBalance " & _
                "FROM V_SalesBalanceInquiry WHERE cInvNo = '" & rsHeader!cInvNo & "' AND cCompanyID = '" & COID & "'"
        rsBalance.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
        
        txtDebit = 0
        txtCredit = 0
        txtReturns = 0
        txtPayment = 0
        txtBalance = 0
        
        If rsBalance.RecordCount <> 0 Then
            txtDebit = rsBalance!nDebit
            txtCredit = rsBalance!nCredit
            txtReturns = rsBalance!nReturns
            txtPayment = rsBalance!nPaid
            txtBalance = rsBalance!nBalance
        End If
        
    Set rsBalance = Nothing

End Sub
'Is check Authorization code?
Function AuthorExisting(Authorization As String, Bank As String, _
            rsExist As ADODB.Recordset, Optional FromDB As Boolean) As Boolean
On Error GoTo err

Dim rsClone As New ADODB.Recordset
Set rsClone = New ADODB.Recordset
    AuthorExisting = False
    
    If FromDB Then
'    If Bank <> "" And Authorization <> "" Then
        sSQL = "SELECT cAuthorization FROM CREDIT_CARD WHERE cAuthorization = '" & Authorization & "' AND cBankID = '" & Bank & "' AND cCompanyID = '" & COID & "'"
'    ElseIf Bank = "" And Authorization <> "" Then
'        sSQL = "SELECT cAuthorization FROM CREDIT_CARD WHERE cAuthorization = '" & Authorization & "' AND cCompanyID = '" & COID & "'"
'    ElseIf Authorization = "" And Bank <> "" Then
'        sSQL = "SELECT cAuthorization FROM CREDIT_CARD WHERE cBankID = '" & Bank & "' AND cCompanyID = '" & COID & "'"
'    End If
    
        Set rs = New Recordset
        rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
        
        If rs.RecordCount <> 0 Then
            AuthorExisting = True
            Set rs = Nothing
            Exit Function
        End If
        Set rs = Nothing
    End If
'    Set rsClone = New ADODB.Recordset
    Set rsClone = rsExist.Clone
    
    rsClone.Filter = "cAuthorization = '" & Authorization & "' AND cBankID = '" & Bank & "'"
    
    If FromDB Then
        If rsClone.RecordCount > 1 Then
            AuthorExisting = True
        End If
    Else
        If rsClone.RecordCount >= 1 Then
            AuthorExisting = True
        End If
    End If
    
    Set rsClone = Nothing
err:
    If err.Number = 91 Then
    End If
End Function
'Public Sub ShowForm(sTranNo As String)
'    If Mode = Find Then
'
'        OpenNewConnection connHeader
'        OpenNewConnection connDetail
'
'        Set rsHeader = Nothing
'        Set rsDetail = Nothing
'        Set rsHeader = New ADODB.Recordset
'        Set rsDetail = New ADODB.Recordset
'
'        OpenRecordsetWithCN rsDetail, "*", "SALES_T", connDetail, "WHERE cInvNo = '" & Trim(sTranNo) & "'"
'        OpenRecordsetWithCN rsHeader, "*", "SALES", connHeader, "WHERE cInvNo = '" & Trim(sTranNo) & "' AND cType = 'Van Selling'"
'
'        Set FrmName = Me
'        FormLocking True
'
'        If rsHeader.RecordCount = 0 Then
'            FormWaitHide
'            MsgBox "No matching record/s found.", vbInformation, "ComUnion Search"
'            RSZero
'            FormSearch True
'            SearchObj True
'            Mode = Find
'            Exit Sub
'        End If
'            SetDataSource
'            SetDataField
'            txtInvNo.BackColor = &HE0FFFF
'            Mode = Normal
'            oBar.BitEnabled Me, ITGLedgerMain.tbrMain, lACNew, lACEdit, lACDelete, , , , , , , True, True, , True, True
'
'    End If
'End Sub


'Is check existing?
Function CheckExisting(CheckNo As String, Bank As String, TranNo As String, _
            rsExist As ADODB.Recordset, Optional FromDB As Boolean) As Boolean

Dim rsClone As New ADODB.Recordset

    CheckExisting = False
    
    If FromDB Then
        sSQL = "SELECT cCheckNo FROM CHECKS WHERE cCheckNo = '" & CheckNo & "' AND cBankID = '" & Bank & "' AND cCompanyID = '" & COID & "'"
        Set rs = New Recordset
        rs.Open sSQL, cn, adOpenForwardOnly, adLockReadOnly
        
        If rs.RecordCount <> 0 Then
            CheckExisting = True
            Set rs = Nothing
            Exit Function
        End If
        Set rs = Nothing
    End If
    
    Set rsClone = rsExist.Clone
    
    rsClone.Filter = "cCheckNo = '" & CheckNo & "' AND cBankID = '" & Bank & "' AND cInvNo = '" & Trim(txtInvNo) & "'"
    
    If FromDB Then
        If rsClone.RecordCount > 1 Then
            CheckExisting = True
        End If
    Else
        If rsClone.RecordCount >= 1 Then
            CheckExisting = True
        End If
    End If
    
    Set rsClone = Nothing
    
End Function

'Inserts into PR & PR_T & PR_C & PR_MAP tables
Private Function SalesReciept() As Boolean
Dim rsPR As New ADODB.Recordset
Dim rsPR_T As New ADODB.Recordset
Dim rsPR_C As New ADODB.Recordset
Dim rsPR_MAP As New ADODB.Recordset
Dim sTran As String


'On Error GoTo SalesRecieptExit
    

    cString = "OR-" & Trim$(rsHeader!cInvNo)
'    sTran = rsDetail!cRefNo
'    rsHeader!cInvNo = Trim(cString)
    
    'FOR REVISION [DO NOT DELETE BECAUSE OF THE IDENTITY] ???????????
    cn.Execute ("DELETE PR WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE PR_T WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE PR_C WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    cn.Execute ("DELETE PR_MAP WHERE cCompanyID = '" & COID & "' AND cTranNo = '" & Trim(cString) & "'")
    
    GetChild
    
    OpenRecordset rsPR, "*", "PR", "WHERE 1 = 0"
    OpenRecordset rsPR_T, "*", "PR_T", "WHERE 1 = 0"
    OpenRecordset rsPR_C, "*", "PR_C", "WHERE 1 = 0"
    OpenRecordset rsPR_MAP, "*", "PR_MAP", "WHERE 1 = 0"
    
    TotalPay
    
    With rsPR
        .AddNew
            !cCompanyID = COID
            !cTranNo = cString
            !cCode = txtCode.Text
            !dDate = dtbDate.Text
            !nCash = rsPayment!nAmount
            !nInvTotal = rsHeader!nGross
            !nPayTotal = nPaid
'            !cRemarks = txtRemarks.Text
    End With

    Do While Not rsPayment.EOF
        With rsPR_T
            .AddNew
            !cCompanyID = COID
            !cTranNo = cString
            !cInvNo = Trim(txtInvNo.Text)
            !dInvDate = dtbDate.Text
            !nInvBalance = rsHeader!nGross - rsPayment!nAmount
            !nApplied = rsPayment!nAmount
            !nEWT = 0
            !nDiscount = 0
            !nEVAT = 0
        End With
        rsPayment.MoveNext
    Loop
    rsPayment.MoveFirst
    Do While Not rsPayment.EOF
        With rsPR_C
            .AddNew
            !cCompanyID = COID
            !cTranNo = cString
            !cType = rsPayment!cType
            !cBankID = rsPayment!cBankID
            !cCheckNo = rsPayment!cCCardNo
            !dCheckDate = rsPayment!dDate
            !nAmount = rsPayment!nAmount
        End With
        rsPayment.MoveNext
    Loop
    
    With rsPR_MAP
            .AddNew
            !cCompanyID = COID
            !cTranNo = cString
            !cInvNo = Trim(txtInvNo.Text)
            !nAmount = rsHeader!nGross
    End With

    
    rsPR.UpdateBatch adAffectAll
    rsPR_T.UpdateBatch adAffectAll
    rsPR_C.UpdateBatch adAffectAll
    rsPR_MAP.UpdateBatch adAffectAll
    
    Set rsPR = Nothing
    Set rsPR_T = Nothing
    Set rsPR_C = Nothing
    Set rsPR_MAP = Nothing
    
'    DRSales = True
    
'SalesRecieptExit:
'    Exit Function
    
End Function

'Inserts into PR & PR_T & PR_C & PR_MAP tables
Private Function SaveCreditCard() As Boolean
Dim rsCC As New ADODB.Recordset
Dim sTran, sType As String


'On Error GoTo SalesRecieptExit
cString = Trim$(rsHeader!cInvNo)

'If sType <> "CSH" Then
cn.Execute ("DELETE CREDIT_CARD WHERE cCompanyID = '" & COID & "' AND nRefNo = '" & Trim(cString) & "'")

GetChild
    
    OpenRecordset rsCC, "*", "CREDIT_CARD", "WHERE 1 = 0"
    
    Do While Not rsPayment.EOF
        If rsPayment!cType = "CC" Then
        With rsCC
            .AddNew
            !cCompanyID = COID
            !cAuthorization = rsPayment!cAuthorization
            !nRefNo = cString
            !cCType = rsPayment!cCCardType
            !cCode = rsHeader!cCode
            !cName = txtName.Text
            !cBankID = rsPayment!cBankID
            !cBankName = GetValueFrTable("cBankName", "BANK", " cBankID = '" & rsPayment!cBankID & "'")
            !cCCardNo = rsPayment!cCCardNo
            !dExpiration = rsPayment!dExpiration
            !nAmount = rsPayment!nAmount
        End With
        End If
        rsPayment.MoveNext
    Loop
    
    rsCC.UpdateBatch adAffectAll
    
    Set rsCC = Nothing
'End If
End Function

Private Sub GetCustFromPM()
On Error GoTo err  'jomz

Dim rsCust As New ADODB.Recordset
Dim connCust As New ADODB.Connection

OpenNewConnection connCust

'if reference in price matrix is equal to customer code (set as default price and discount for subjected item)
If GetValueFrTable("cReference", "PM a inner join pm_t b ON b.cCompanyID = a.cCompanyID AND b.cPMID = a.cPMID ", "cItemNo = '" & rsDetail!cItemNo & "' and dEffectDate <= '" & Date & "' and lCancelled = 0 and a.cCompanyID = '" & COID & "' and a.cType = 'Customer' and a.lPosted = 1 and a.lApproved = 1", True) = rsHeader!cCode Then
    rsDetail!cPricing = "Pricing Client"
    rsDetail!nUDPrice = GetValueFrTable("nPrice", "PM a inner join pm_t b ON b.cCompanyID = a.cCompanyID AND b.cPMID = a.cPMID ", "cItemNo = '" & rsDetail!cItemNo & "' and dEffectDate <= '" & Date & "' and lCancelled = 0 and a.cCompanyID = '" & COID & "' and lPosted = 1 and lApproved = 1", True)
    rsDetail!cDiscount = GetValueFrTable("cDiscount", "PM a inner join pm_t b ON b.cCompanyID = a.cCompanyID AND b.cPMID = a.cPMID ", "cItemNo = '" & rsDetail!cItemNo & "' and dEffectDate <= '" & Date & "' and lCancelled = 0 and a.cCompanyID = '" & COID & "' and lPosted = 1 and lApproved = 1", True)
Exit Sub 'exit when true
End If

'get customer type if is member of wholesaler
If GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cCode & "'", True) = "Member" Then
    'Or GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cCode & "'", True) = "Wholesaler" Then 'Exit Sub
    
    If IsNull(rsDetail!cPricing) Then
        'set pricing to customer type
        rsDetail!cPricing = GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cCode & "'", True)
    End If
    
    
    sSQL = "Select nPrice,cDiscount from PM_T a inner join pm b " _
            & "ON b.cCompanyID = a.cCompanyID AND b.cPMID = a.cPMID " _
            & "where cReference = '" & GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cCode & "'", True) & "' and cItemNo = '" & rsDetail!cItemNo & "' " _
            & "and dEffectDate <= '" & Date & "' and lCancelled = 0 and b.cCompanyID = '" & COID & "' and b.lPosted = 1 and b.lApproved = 1"
    
    rsCust.Open sSQL, connCust, adOpenStatic, adLockOptimistic
    
    If rsCust.RecordCount = 0 Or (rsDetail!cPricing <> GetValueFrTable("cCustomerType", "CLIENT_CUSTOMER", "cCode = '" & rsHeader!cCode & "'", True)) Then
        rsDetail!nUDPrice = 0
        rsDetail!cDiscount = ""
    Else
        rsDetail!nUDPrice = rsCust!nPrice
        rsDetail!cDiscount = rsCust!cDiscount
    End If
Else
    rsDetail!cPricing = "SRP"
    Exit Sub
End If
err: Exit Sub
End Sub

Private Sub TotalPay()
Dim rsTPay As New ADODB.Recordset
Dim connTPay As New ADODB.Connection


OpenNewConnection connTPay

sSQL = "SELECT SUM(nAmount) as nAmount FROM SALES_P WHERE cInvNo = '" & Trim(txtInvNo.Text) & "'"

rsTPay.Open sSQL, connTPay, adOpenStatic, adLockOptimistic

nPaid = rsTPay!nAmount

End Sub

Private Sub TotalAmount()
On Error Resume Next
nAmount = 0
nPAmount = 0
nCash = 0
rsPayment!nAmount = 0

    If rsPayment.RecordCount > 0 Then
    rsPayment.MoveFirst
    Do While Not rsPayment.EOF
        nPAmount = nPAmount + rsPayment!nAmount
        rsPayment.MoveNext
    Loop
    End If
    rsPayment.MoveLast
    
    If rsPayment.RecordCount > 0 Then
    rsPayment.MoveFirst
    Do While Not rsPayment.EOF
        nCash = nCash + rsPayment!nCash
        rsPayment.MoveNext
    Loop
    End If
    rsPayment.MoveLast
    
    rsDetail.MoveFirst
    Do While Not rsDetail.EOF
        nAmount = nAmount + rsDetail!nAmount
        rsDetail.MoveNext
    Loop
    rsDetail.MoveLast
End Sub

Public Sub TBAccountAffected()
    If rsHeader!lCancelled = 0 Then
        RepName = "SALES"
        frmAccountAffected.mModuleType = KSALES
        frmAccountAffected.mRefPK = txtInvNo.Text
        frmAccountAffected.Show vbModal
    End If
End Sub
